package farmers.html;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * 教程网址
 * https://blog.csdn.net/weixin_29882269/article/哈哈details/112078260
 */
public class Jsoup_Javcup {
    public static void main(String[] args) throws IOException {

//        https://javcup.com/movie/GHOV-037

        for (int seq = 1; seq <= 1; seq++) {


            String httpUrl = "https://javcup.com/movie/GHOV-" + String.format("%03d", seq);
            System.out.println(httpUrl);



            Document document = Jsoup.connect(httpUrl).get();
//            System.out.println(document);



            // 标题
            Elements elements_title = document.getElementsByClass("title title-multi-ellipsis card-title");
            System.out.println(elements_title);
            elements_title.forEach(title -> {
                System.out.println(title.html());
            });



            // 视频图片
            Elements class_img = document.getElementsByTag("video");
            System.out.println(class_img);
            class_img.forEach(img -> {
                String poster = img.attr("poster");
                System.out.println(poster);
            });
            // 查找元素
            // getElementById(String id)
            // getElementsByTag(String tag)
            // getElementsByClass(String className)
            // getElementsByAttribute(String key)
//        Element activityName = document.getElementById("activity-name");
//        System.out.println(activityName);
            // <h1 class="rich_media_title " id="activity-name"> 上海昨日新增本土2494+16407！居住地详情公布 </h1>


//        可以用下列方法提取元素的数据：
//
//        attr(String key)获取元素key属性的值
//        attributes()获取元素所有属性
//        id()获取元素id属性的值
//        className和classNames获取元素class属性的值
//        text()获取元素内容


        }
    }


    public static void add(StringBuffer sb, String str){
        sb.append(str + "\t");
    }

}